//统一管理用户请求相关api
//引入自己封装的axios对象
import request from "@/utils/request";
import type { checkPwdResponseData, loginFormData,loginResponseData,pwdData,userAddResponseData,userAllResponseData,userInfoData,userInfoResponseData, userListFormData, userListResponseData, userRemoveResponseData } from "./type.ts";
//定义用户相关的请求地址
//@ts-ignore
enum API{
    LOGIN_URL = "/login",
    USERINFO_URL = "/user/info",
    LOGOUT_URL = "/logout",
    CHECK_PWD_URL = "/manage/user/pwd",
    GET_ALL_USERS = "/manage/user/all",
    GET_Page_USERS = "/manage/user/list",
    ADD_USER = "/manage/user/add",
    UPDATE_USER = "/manage/user/update",
    FIND_BY_ID = "/manage/user/find",
    DELETE_USER = "/manage/user/delete"
}
//登录请求接口
export const reqLogin = (data:loginFormData)=>request.post<any,loginResponseData>(API.LOGIN_URL,data);
//获取用户信息
export const reqUserInfo = ()=>request.post<any,userInfoResponseData>(API.USERINFO_URL)
//退出登录
export const reqLogout = ()=>request.post<any,any>(API.LOGOUT_URL)
//校验密码
export const reqCheckPwd = (data:pwdData)=>request.post<any,checkPwdResponseData>(API.CHECK_PWD_URL,data)
//修改密码
export const reqUpdatePwd = (data:pwdData)=>request.put<any,checkPwdResponseData>(API.CHECK_PWD_URL,data)
//获取用户列表
export const reqUserAll = ()=>request.get<any,userAllResponseData>(API.GET_ALL_USERS);
//获取用户列表(分页查询)
export const reqUserPage = (data:userListFormData)=>request.post<any,userListResponseData>(API.GET_Page_USERS,data)
//新增用户
export const reqUserAdd = (data:userInfoData)=>request.post<any,userAddResponseData>(API.ADD_USER,data);
//更新用户
export const reqUserUpdate = (data:userInfoData)=>request.post<any,userAddResponseData>(API.UPDATE_USER,data);
//通过id获取用户
export const reqUserFindById = (_id:string)=>request.get<any,userAddResponseData>(API.FIND_BY_ID+`?_id=${_id}`)
//删除用户
export const reqUserRemove = (userId:string)=>request.post<any,userRemoveResponseData>(API.DELETE_USER,{userId})
